
// Open MoneySpinner Suite v1
// An open source business management software system written in Java and MySQL
// Recommended IDE is NetBeans IDE 7.0.1
// Support Web Site: http://www.milliscript.com
//
// Copyright (C) 2014, Abiodun Aremu, Ibadan/NIGERIA.
// Open MoneySpinner Suite is distributed under the terms of the Apache License version 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package openmoneyspinnersuite;

/**
 *
 * @author Abiodun Aremu
 */

import java.sql.*;
import javax.swing.*;

final class StockReport extends javax.swing.JInternalFrame {
    Object[][] tableObject=new Object[][]{};
    Systems systems=new Systems();
    PreparedStatement statement;
    Thread processThread=new Thread();
    Thread titleThread=new Thread();
    /** Creates new form ViewCredit */
     StockReport() {
        initComponents();
        /* Execute refresh thread */
        processThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                resetTable();
                resetCombo();
            }
        });
        titleThread=new Thread(new Runnable() {
            public void run() {
                while(processThread.isAlive())setProcessingTitle(titleThread);
                enableControls();
                System.out.println("viewStockReportThread stopped runing.");
            }
        });
        processThread.start();
        titleThread.start();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jRefreshButton = new javax.swing.JButton();
        jCancelButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jItemComboBox = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jItemNameTextField = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jMonthComboBox = new javax.swing.JComboBox();
        jYearComboBox = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(openmoneyspinnersuite.OpenMS_Finance_App.class).getContext().getResourceMap(StockReport.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setToolTipText(resourceMap.getString("Form.toolTipText")); // NOI18N
        setFrameIcon(resourceMap.getIcon("Form.frameIcon")); // NOI18N
        setName("Form"); // NOI18N
        setVisible(true);

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Date", "Opening Stock", "Quantity Sold", "Amount Sold", "Aggregate Quantity Sold", "Aggregate Amount Sold", "Closing Stock", "Stock Count", "Stock Difference", "Shortfall", "Quantity Unit", "Amount Unit"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable1.columnModel.title0")); // NOI18N
        jTable1.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable1.columnModel.title1")); // NOI18N
        jTable1.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("jTable1.columnModel.title7")); // NOI18N
        jTable1.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("jTable1.columnModel.title2")); // NOI18N
        jTable1.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("jTable1.columnModel.title6")); // NOI18N
        jTable1.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("jTable1.columnModel.title3")); // NOI18N
        jTable1.getColumnModel().getColumn(6).setHeaderValue(resourceMap.getString("jTable1.columnModel.title6")); // NOI18N
        jTable1.getColumnModel().getColumn(7).setHeaderValue(resourceMap.getString("jTable1.columnModel.title7")); // NOI18N
        jTable1.getColumnModel().getColumn(8).setHeaderValue(resourceMap.getString("jTable1.columnModel.title10")); // NOI18N
        jTable1.getColumnModel().getColumn(9).setHeaderValue(resourceMap.getString("jTable1.columnModel.title11")); // NOI18N
        jTable1.getColumnModel().getColumn(10).setHeaderValue(resourceMap.getString("jTable1.columnModel.title8")); // NOI18N
        jTable1.getColumnModel().getColumn(11).setHeaderValue(resourceMap.getString("jTable1.columnModel.title9")); // NOI18N

        jRefreshButton.setIcon(resourceMap.getIcon("jRefreshButton.icon")); // NOI18N
        jRefreshButton.setText(resourceMap.getString("jRefreshButton.text")); // NOI18N
        jRefreshButton.setName("jRefreshButton"); // NOI18N
        jRefreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRefreshButtonActionPerformed(evt);
            }
        });

        jCancelButton.setIcon(resourceMap.getIcon("jCancelButton.icon")); // NOI18N
        jCancelButton.setText(resourceMap.getString("jCancelButton.text")); // NOI18N
        jCancelButton.setName("jCancelButton"); // NOI18N
        jCancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCancelButtonActionPerformed(evt);
            }
        });

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jItemComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --" }));
        jItemComboBox.setName("jItemComboBox"); // NOI18N
        jItemComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jItemComboBoxActionPerformed(evt);
            }
        });

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jItemNameTextField.setEditable(false);
        jItemNameTextField.setText(resourceMap.getString("jItemNameTextField.text")); // NOI18N
        jItemNameTextField.setEnabled(false);
        jItemNameTextField.setName("jItemNameTextField"); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel1.border.title"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
        jTextField1.setEnabled(false);
        jTextField1.setName("jTextField1"); // NOI18N

        jTextField2.setText(resourceMap.getString("jTextField2.text")); // NOI18N
        jTextField2.setEnabled(false);
        jTextField2.setName("jTextField2"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 299, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 299, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(27, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(21, Short.MAX_VALUE))
        );

        jMonthComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Month --" }));
        jMonthComboBox.setName("jMonthComboBox"); // NOI18N
        jMonthComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMonthComboBoxActionPerformed(evt);
            }
        });

        jYearComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Year --" }));
        jYearComboBox.setName("jYearComboBox"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 841, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(122, 122, 122)
                        .addComponent(jRefreshButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jCancelButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jItemNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jItemComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jMonthComboBox, 0, 142, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jYearComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jItemComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(11, 11, 11)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jItemNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jMonthComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jYearComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jRefreshButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jRefreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRefreshButtonActionPerformed
        if(jItemComboBox.getSelectedItem().toString().equalsIgnoreCase("-- Select "))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE SELECT AN ITEM CODE !","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;            
        }
//        if(jMonthComboBox.getSelectedItem().toString().equalsIgnoreCase("-- Month --"))
//        {
//            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE SELECT REPORT MONTH !","ERROR !",JOptionPane.ERROR_MESSAGE);
//            return;            
//        }
        if(jYearComboBox.getSelectedItem().toString().equalsIgnoreCase("-- Year --"))
        
{
            
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"PLEASE SELECT REPORT YEAR !","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;            
        
}
        
/* Execute refresh thread */
        processThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                refreshTable();
            }
        });
        titleThread=new Thread(new Runnable() {
            public void run() {
                while(processThread.isAlive())setProcessingTitle(titleThread);
                enableControls();
                System.out.println("viewStockReportThread stopped runing.");
            }
        });
        processThread.start();
        titleThread.start();
    }//GEN-LAST:event_jRefreshButtonActionPerformed
     void reset()
    {
        /* Execute refresh thread */
        processThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                refreshTable();
            }
        });
        titleThread=new Thread(new Runnable() {
            public void run() {
                while(processThread.isAlive())setProcessingTitle(titleThread);
                enableControls();
                System.out.println("viewStockReportThread stopped runing.");
            }
        });
        processThread.start();
        titleThread.start();
    }
                                  
    public void resetYear()
    {
        String[] year=systems.getYears(1920);
        year[0]="-- Year --";
        jYearComboBox.setModel(new DefaultComboBoxModel(year));
    }
    public void resetMonth()
    {
        String[] month=systems.getMonthArray();
        month[0]="-- Month --";

        jMonthComboBox.setModel(new DefaultComboBoxModel(month));

    }
    private void setProcessingTitle(Thread thread)
    {
        try{
            this.setTitle("::. View Stock Report - Processing Request");
            thread.sleep(500);
            this.setTitle("::. View Stock Report - Processing Request.");
            thread.sleep(500);
            this.setTitle("::. View Stock Report - Processing Request..");
            thread.sleep(500);
            this.setTitle("::. View Stock Report - Processing Request...");
            thread.sleep(500);
        }catch(Exception e){System.out.println("Title thread"+e);}
    }
    private void jCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCancelButtonActionPerformed
        
        
if(processThread.isAlive())
        {
            try{
                
processThread.stop();
                
titleThread.stop();
                
System.out.println("Threads successfully stopped.");
            
}catch(Exception e){
System.out.println("Thread stopping error: "+e);
}
            
this.setTitle("::. View Stock Report");
            
enableControls();
        
}
        
else
        dispose();
    
}//GEN-LAST:event_jCancelButtonActionPerformed

    
private void jItemComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jItemComboBoxActionPerformed
        
jItemComboBoxSelected();
    
}
//GEN-LAST:event_jItemComboBoxActionPerformed

private void jMonthComboBoxActionPerformed(java.awt.event.ActionEvent evt) 
{//GEN-FIRST:event_jMonthComboBoxActionPerformed

}//GEN-LAST:event_jMonthComboBoxActionPerformed
    
private void jItemComboBoxSelected()
    
{
        
String itemCode=jItemComboBox.getSelectedItem().toString();
        if(itemCode.equals("-- Select --")==false)
        
{
            
String itemName=systems.getValue(OpenMSApp.Database_A,"Select * from Item where cItemCode='"+itemCode+"'",2);
            
jItemNameTextField.setText(itemName);
        
}
        
else
            
resetItemCombo();
    
}
    
void resetItemCombo()
    
{
        
String[] itemCode=systems.getTableDataArray(OpenMSApp.Database_A," Item where cType='Stock'",1);
        
itemCode[0]="-- Select --";
        
jItemComboBox.setModel(new DefaultComboBoxModel(itemCode));        
    
}
    
void resetCombo()
    
{
        
resetItemCombo();
        
resetYear();
        
resetMonth();
    
}
    
private void disableControls()
    
{
        
jRefreshButton.setEnabled(false);
        
jItemComboBox.setEnabled(false);
    
}
    
private void enableControls()
    
{
        
jRefreshButton.setEnabled(true);
        
jItemComboBox.setEnabled(true);
        
this.setTitle("::. View Stock Report");
    
}

    
void resetTable()
    
{
        
jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "Date", "Opening Stock", "Stock Received", "Stock Issued", "Quantity Sold", "Amount Sold", "Aggregate Quantity Sold", "Aggregate Amount Sold", "Closing Stock", "Stock Count", "Stock Difference", "Supply Shortfall", "Quantity Unit", "Amount Unit"
            }
        ) 
{
            
boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
    }
     void print()
    {
        try
        {
            jTable1.print();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    void refreshTable()
    {
        String[] reportDays={};int y=0;
        if(jMonthComboBox.getSelectedItem().toString().equalsIgnoreCase("-- Month --")==false){
            reportDays=systems.getDays(jMonthComboBox.getSelectedItem().toString());
            y=reportDays.length-1;
        }
        else{
            reportDays=new String[]{"","01","02","03","04","05","06","07","08","09","10","11","12"};
            y=reportDays.length-1;
        }
        String itemCode=jItemComboBox.getSelectedItem().toString();
        System.out.println("item code : "+itemCode);
        String itemUnitCode=systems.getValue(OpenMSApp.Database_A,"Select * from Item where cItemCode='"+itemCode+"'",9);        
        int x=1;
        
        System.out.println("Length of report days= "+y);
        String sumQtyValue="0";
        String sumAmtValue="0";
            String itemUnit;
            String totQtySold;
            String totQtyCredited;
            String totQtyDebited;
            String totAmtSold;
            String openingStock;
            String closingStock;
            String stockCountRecord[];
            String stockShortfall;
            String stockCount;
            String itemAccountCode;
            String itemActUnit;
        tableObject=new Object[y][14];

        
while(x<=y)
        
{
            
itemUnit=systems.getValue(OpenMSApp.Database_A, "Select * from itemUnit where cItemUnitCode='"+itemUnitCode+"'", 2);
            
if(jMonthComboBox.getSelectedItem().toString().equalsIgnoreCase("-- Month --")==false)
            
{
                
totQtySold=systems.getItemTotalRevenueQty(itemCode, "'"+jYearComboBox.getSelectedItem().toString()+"/"+systems.getMonthDigit(jMonthComboBox.getSelectedItem().toString())+"/"+x+" 00:00:00'", "'"+jYearComboBox.getSelectedItem().toString()+"/"+systems.getMonthDigit(jMonthComboBox.getSelectedItem().toString())+"/"+x+" 23:59:59'");
                
totQtyCredited=systems.getItemTotalIRCreditQty(itemCode, "'"+jYearComboBox.getSelectedItem().toString()+"/"+systems.getMonthDigit(jMonthComboBox.getSelectedItem().toString())+"/"+x+" 00:00:00'", "'"+jYearComboBox.getSelectedItem().toString()+"/"+systems.getMonthDigit(jMonthComboBox.getSelectedItem().toString())+"/"+x+" 23:59:59'");
                
totQtyDebited=systems.getItemTotalIRDebitQty(itemCode, "'"+jYearComboBox.getSelectedItem().toString()+"/"+systems.getMonthDigit(jMonthComboBox.getSelectedItem().toString())+"/"+x+" 00:00:00'", "'"+jYearComboBox.getSelectedItem().toString()+"/"+systems.getMonthDigit(jMonthComboBox.getSelectedItem().toString())+"/"+x+" 23:59:59'");
                
totAmtSold=systems.getItemTotalRevenueAmount(itemCode, "'"+jYearComboBox.getSelectedItem().toString()+"/"+systems.getMonthDigit(jMonthComboBox.getSelectedItem().toString())+"/"+x+" 00:00:00'", "'"+jYearComboBox.getSelectedItem().toString()+"/"+systems.getMonthDigit(jMonthComboBox.getSelectedItem().toString())+"/"+x+" 23:59:59'");
                openingStock=systems.getItemQuantityAvailable(itemCode,"'1920/1/1 00:00:00'", "DATE_SUB('"+jYearComboBox.getSelectedItem().toString()+"/"+systems.getMonthDigit(jMonthComboBox.getSelectedItem().toString())+"/"+x+" 23:59:59',INTERVAL 1 DAY)");
                
closingStock=systems.getItemQuantityAvailable(itemCode,"'1920/1/1 00:00:00'", "'"+jYearComboBox.getSelectedItem().toString()+"/"+systems.getMonthDigit(jMonthComboBox.getSelectedItem().toString())+"/"+x+" 23:59:59'");
                
stockCountRecord=systems.getValue(OpenMSApp.Database_A, "Select * from stockCount where cItemCode='"+itemCode+"' and cast(dDate as date)='"+jYearComboBox.getSelectedItem().toString()+"/"+systems.getMonthDigit(jMonthComboBox.getSelectedItem().toString())+"/"+x+"'", 3,5);                
          
            }
            
else{
                
totQtySold=systems.getItemTotalRevenueQty(itemCode, "'"+jYearComboBox.getSelectedItem().toString()+"/"+reportDays[x]+"/01 00:00:00'", "'"+jYearComboBox.getSelectedItem().toString()+"/"+reportDays[x]+"/"+systems.getMonthMaximumDay(systems.getMonthName(reportDays[x])) +" 23:59:59'");
                
totQtyCredited=systems.getItemTotalIRCreditQty(itemCode, "'"+jYearComboBox.getSelectedItem().toString()+"/"+reportDays[x]+"/01 00:00:00'", "'"+jYearComboBox.getSelectedItem().toString()+"/"+reportDays[x]+"/"+systems.getMonthMaximumDay(systems.getMonthName(reportDays[x]))+" 23:59:59'");
                
totQtyDebited=systems.getItemTotalIRDebitQty(itemCode, "'"+jYearComboBox.getSelectedItem().toString()+"/"+reportDays[x]+"/01 00:00:00'", "'"+jYearComboBox.getSelectedItem().toString()+"/"+reportDays[x]+"/"+systems.getMonthMaximumDay(systems.getMonthName(reportDays[x]))+" 23:59:59'");
                
totAmtSold=systems.getItemTotalRevenueAmount(itemCode, "'"+jYearComboBox.getSelectedItem().toString()+"/"+reportDays[x]+"/01 00:00:00'", "'"+jYearComboBox.getSelectedItem().toString()+"/"+reportDays[x]+"/"+systems.getMonthMaximumDay(systems.getMonthName(reportDays[x]))+" 23:59:59'");

                
openingStock=systems.getItemQuantityAvailable(itemCode,"'1920/1/1 00:00:00'", "DATE_SUB('"+jYearComboBox.getSelectedItem().toString()+"/"+reportDays[x]+"/01 23:59:59',INTERVAL 1 DAY)");
                
closingStock=systems.getItemQuantityAvailable(itemCode,"'1920/1/1 00:00:00'", "'"+jYearComboBox.getSelectedItem().toString()+"/"+reportDays[x]+"/"+systems.getMonthMaximumDay(systems.getMonthName(reportDays[x]))+" 23:59:59'");
                
stockCountRecord=systems.getValue(OpenMSApp.Database_A, "Select * from stockCount where cItemCode='"+itemCode+"' and cast(dDate as date)='"+jYearComboBox.getSelectedItem().toString()+"/"+reportDays[x]+"/"+systems.getMonthMaximumDay(systems.getMonthName(reportDays[x]))+"'", 3,5);                
            }
            
//stockCountRecord=systems.getValue(OpenMSApp.Database_A, "Select * from stockCount where cItemCode='"+itemCode+"' and cast(dDate as date)='"+jYearComboBox.getSelectedItem().toString()+"/"+systems.getMonthInt(jMonthComboBox.getSelectedItem().toString())+"/"+x+"'", 3,5);
            stockShortfall=stockCountRecord[1];
            
stockCount=stockCountRecord[0];
            
itemAccountCode=systems.getValue(OpenMSApp.Database_A, "Select * from creditorder join creditOrdersummary on creditOrderSummary.cCreditOrderCode=creditOrder.cCreditOrderCode where creditOrderSummary.cItemCode='"+
            itemCode+"'", 3);
            
itemActUnit=systems.getValue(OpenMSApp.Database_A, "Select * from account where cAccountCode='"+itemAccountCode+"'", 5);
            
if(totQtySold==null||totQtySold.isEmpty())totQtySold="N/A";
            
if(totAmtSold==null||totAmtSold.isEmpty())totAmtSold="N/A";
            
if(openingStock==null||openingStock.isEmpty())openingStock="N/A";
            
if(stockCount==null||stockCount.isEmpty())stockCount="N/A";
            
if(stockShortfall==null||stockShortfall.isEmpty())stockShortfall="N/A";
            
if(itemAccountCode==null)itemActUnit="N/A";
            
if(jMonthComboBox.getSelectedItem().toString().equalsIgnoreCase("-- Month --")==false)
                
tableObject[x-1][0]=reportDays[x]+"/"+systems.getMonthDigit(jMonthComboBox.getSelectedItem().toString())+"/"+jYearComboBox.getSelectedItem().toString();
            
else
                
tableObject[x-1][0]=systems.getMonthName(reportDays[x])+"/"+jYearComboBox.getSelectedItem().toString();
            
tableObject[x-1][1]=openingStock;
            
tableObject[x-1][2]=totQtyCredited;  
            
tableObject[x-1][3]=totQtyDebited;            
            
tableObject[x-1][4]=totQtySold;
            
tableObject[x-1][5]=totAmtSold;
            
if(totQtySold.equalsIgnoreCase("N/A"))
            
tableObject[x-1][6]="N/A";
            
else
            
tableObject[x-1][6]=sumQtyValue=systems.getValue(OpenMSApp.Database_A, "Select "+sumQtyValue+" + "+totQtySold+" AS 'Sum' ", 1);
            
if(totAmtSold.equalsIgnoreCase("N/A"))
            
tableObject[x-1][7]="N/A";
            
else
            
tableObject[x-1][7]=sumAmtValue=systems.getValue(OpenMSApp.Database_A, Connect.procInit+"  prnAddMoney"+Connect.procInitStart+""+sumAmtValue+" , "+totAmtSold+Connect.procInitEnd, "mSumValue");
            
tableObject[x-1][8]=closingStock;
            
tableObject[x-1][9]=stockCount;
            
if(stockCount.equalsIgnoreCase("N/A"))
            
tableObject[x-1][10]="N/A";
            
else
            
tableObject[x-1][10]=systems.getValue(OpenMSApp.Database_A, "Select "+closingStock+" - "+stockCount+" AS 'Sum' ", 1);
            
tableObject[x-1][11]=stockShortfall;
            
tableObject[x-1][12]=itemUnit;
            
tableObject[x-1][13]=itemActUnit;
            
systems.freeHeap();
            
//Connect.closeMainConnection();
            
//Connect.createMSSQLConnection();
            
x+=1;
            
if(x>y){break;}
       
}
        
jTextField1.setText(sumQtyValue);
        
jTextField2.setText(sumAmtValue);
        
jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "Date", "Opening Stock", "Stock Received", "Stock Issued", "Quantity Sold", "Amount Sold", "Aggregate Quantity Sold", "Aggregate Amount Sold", "Closing Stock", "Stock Count", "Stock Difference", "Supply Shortfall", "Quantity Unit", "Amount Unit"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        Connect.closeMainConnection();
        Connect.createMSSQLConnection();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jCancelButton;
    private javax.swing.JComboBox jItemComboBox;
    private javax.swing.JTextField jItemNameTextField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JComboBox jMonthComboBox;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton jRefreshButton;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JComboBox jYearComboBox;
    // End of variables declaration//GEN-END:variables

}
